package com.gitee.swsk33.dbuser.service.impl;

import com.gitee.swsk33.dbentity.dataobject.User;
import com.gitee.swsk33.dbentity.model.Result;
import com.gitee.swsk33.dbuser.dao.UserDAO;
import com.gitee.swsk33.dbuser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDAO userDAO;

	@Override
	public Result<User> getById(int id) {
		Result<User> result = new Result<>();
		User getUser = userDAO.selectById(id);
		if (getUser == null) {
			result.setResultFailed("用户不存在！");
			return result;
		}
		result.setResultSuccess("查找成功！", getUser);
		return result;
	}

	@Override
	public Result<List<User>> getAll() {
		Result<List<User>> result = new Result<>();
		List<User> getUsers = userDAO.selectList(null);
		result.setResultSuccess("查找完成！", getUsers);
		return result;
	}

}